home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 53696 / 53696.xpi / chrome / content / glide.js < prev    next >
Text File  |  2010-01-21  |  29KB  |  910 lines

  1. var $jq = jQuery.noConflict();
  2.  
  3. var glideSession = {
  4.     token: null,
  5.     username: null,
  6.     userId: null,
  7.     accountId: null,
  8.     email: null,
  9.     fullName: null,
  10.     clear: function() {
  11.         this.token = null;
  12.         this.username = null;
  13.         this.userId = null;
  14.         this.accountId = null;
  15.         this.email = null;
  16.         this.fullName = null;
  17.     },
  18.     load: function(d) {
  19.         this.token = d.token;
  20.         this.username = d.username;
  21.         this.userId = d.userId;
  22.         this.accountId = d.accountId;
  23.         this.email = d.email;
  24.         this.fullName = d.fullName;
  25.     }
  26. };
  27.  
  28. var glideExtension = function() {
  29.     var 
  30.         APP_STORAGE_SESSION_KEY = "glidelife.com",
  31.         GLIDE_REGISTER_URL = "https://account.glidesociety.com/register/default.aspx?returnUrl=http://www.glidelife.com",
  32.         GLIDE_API_URL = "http://alpha.glidelife.com/api",
  33.         GLIDE_API_URL_SECURE = "https://alpha.glidelife.com/api",
  34.         GLIDE_DESKTOP_URL = "http://desktop.glidesociety.com",
  35.         GLIDE_PUBLIC_URL = "http://www.glidesociety.com",
  36.         GLIDE_URL = "http://alpha.glidelife.com",
  37.         GLIDE_WEBMAIL_URL = "http://webmail.glidefree.com",
  38.         ENDPOINT_FS = "/fs/default.aspx",
  39.         ENDPOINT_SESSION = "/session/default.aspx",
  40.         EMPTY_GUID = "00000000-0000-0000-0000-000000000000",
  41.         LOGIN_REALM = "Glide OS Login",
  42.         PAGE_SIZE = 10,
  43.         PAGE_SIZE_LARGE = 40,
  44.         CAPTURE_TYPES = [
  45.             { label: "Glide Write", type: "write" },
  46.             { label: "PDF", type: "pdf" },
  47.             { label: "Word 2007", type: "word2007" },
  48.             { label: "Word (97/2003/XP)", type: "word" },
  49.             { label: "RTF", type: "rtf" }
  50.         ],
  51.         CAPTURE_TYPE_IMAGE = "image",
  52.         DISABLE_URLS = [
  53.             { url: "about:" },
  54.             { url: "chrome:" },
  55.             { url: "webmail.glidefree.com" },
  56.             { url: "glidelife.com" },
  57.             { url: "account.glidesociety.com" },
  58.             { url: "desktop.glidesociety.com" },
  59.             { url: "www.glidesociety.com/site.aspx" },
  60.             { url: "www.glidesociety.com/user.aspx" },
  61.             { url: "xmobile.glidesociety.com" },
  62.             { url: "xservice.glidesociety.com" }
  63.         ],
  64.         REUSE_WINDOW_URLS = [
  65.             "about:blank",
  66.             "about:config",
  67.             "webmail.glidefree.com",
  68.             "glidelife.com/glide.aspx",
  69.             "desktop.glidesociety.com/upload.aspx",
  70.             "xservice.glidesociety.com"
  71.         ],
  72.         application = Components.classes["@mozilla.org/fuel/application;1"].getService(Components.interfaces.fuelIApplication),
  73.         preferences = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch),
  74.         prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService),
  75.         loginManager = Components.classes["@mozilla.org/login-manager;1"].getService(Components.interfaces.nsILoginManager),
  76.  
  77.         getCurrentDocument = function() {
  78.             return gBrowser.contentDocument;
  79.         },
  80.  
  81.         isWindowReuseable = function() {
  82.             var location = getCurrentDocument().location.href.toLowerCase();
  83.  
  84.             for (var i = 0; i < REUSE_WINDOW_URLS.length; i++) {
  85.                 if (location.indexOf(REUSE_WINDOW_URLS[i].toLowerCase()) >= 0)
  86.                     return true;
  87.             }
  88.  
  89.             return false;
  90.         },
  91.  
  92.         updateUI = function() {
  93.             var location = getCurrentDocument().location.href.toLowerCase();
  94.             var hide = false;
  95.  
  96.             for (var i = 0; i < DISABLE_URLS.length; i++) {
  97.                 if (location.indexOf(DISABLE_URLS[i].url.toLowerCase()) >= 0) {
  98.                     hide = true;
  99.  
  100.                     break;
  101.                 }
  102.             }
  103.  
  104.             document.getElementById("glide-menu-glide-login").hidden = glideSession.token != null;
  105.             document.getElementById("glide-menu-glide-register").hidden = glideSession.token != null;
  106.             document.getElementById("glide-menu-glide-login-sep").hidden = glideSession.token != null;
  107.             document.getElementById("glide-menu-glide-logout-sep").hidden = null == glideSession.token;
  108.             document.getElementById("glide-menu-glide-logout").hidden = null == glideSession.token;
  109.             document.getElementById("glide-menu-bin-add").hidden = hide;
  110.             document.getElementById("glide-menu-bin-add-sep").hidden = hide;
  111.             document.getElementById("glide-capture-toolbar").disabled = hide;
  112.             document.getElementById("glide-menu-sync-import").hidden = hide;
  113.             document.getElementById("glide-menu-sync-import-sep").hidden = hide;
  114.             document.getElementById("glide-menu-social-add-post").hidden = hide;
  115.             document.getElementById("glide-menu-social-add-group").hidden = hide;
  116.             document.getElementById("glide-menu-social-add-sep").hidden = hide;
  117.             document.getElementById("glide-menu-email-add").hidden = hide;
  118.             document.getElementById("glide-menu-email-add-sep").hidden = hide;
  119.             document.getElementById("glide-menu-groups-add").hidden = hide;
  120.             document.getElementById("glide-menu-groups-add-sep").hidden = hide;
  121.             document.getElementById("glide-menu-meeting-add").hidden = hide;
  122.             document.getElementById("glide-menu-meeting-add-sep").hidden = hide;
  123.             document.getElementById("glide-menu-write-add").hidden = hide;
  124.             document.getElementById("glide-menu-write-add-sep").hidden = hide;
  125.         },
  126.  
  127.         openToolbarButton = function(who) {
  128.             if (who && !who.open && !who.disabled) {
  129.                 var toolbarButton = null;
  130.                 var toolbarButtons = who.parentNode.getElementsByTagName("toolbarbutton");
  131.                 var toolbarButtonsLength = toolbarButtons.length;
  132.  
  133.                 for (var i = 0; i < toolbarButtonsLength; i++) {
  134.                     toolbarButton = toolbarButtons.item(i);
  135.  
  136.                     if (toolbarButton && toolbarButton != who && toolbarButton.open) {
  137.                         toolbarButton.open = false;
  138.                         who.open = true;
  139.  
  140.                         break;
  141.                     }
  142.                 }
  143.             }
  144.         },
  145.  
  146.         tabSelected = function() {
  147.             updateUI();
  148.         },
  149.  
  150.         init = function() {
  151.             var location = getCurrentDocument().location.href;
  152.  
  153.             updateUI();
  154.         },
  155.  
  156.         loadUrl = function(url) {
  157.             window._content.document.location = url;
  158.             window.content.focus();
  159.         },
  160.  
  161.         loadUrlInNewWindow = function(url, width, height, extras) {
  162.             if (!width)
  163.                 return window.open(url, "glide_" + new Date().getTime(), "toolbar=yes,directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes");
  164.  
  165.             if (undefined == extras || !extras)
  166.                 return window.open(url, "glide_" + new Date().getTime(), "width=" + width + ",height=" + height + ",toolbar=no,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no");
  167.  
  168.             return window.open(url, "glide_" + new Date().getTime(), "width=" + width + ",height=" + height + ",toolbar=yes,directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=yes");
  169.         },
  170.  
  171.         loadUrlInTab = function(url) {
  172.             if (isWindowReuseable()) {
  173.                 loadUrl(url);
  174.  
  175.                 return;
  176.             }
  177.  
  178.             var t = getBrowser().addTab(url);
  179.  
  180.             getBrowser().selectedTab = t;
  181.         },
  182.  
  183.         invokeService = function(endpoint, method, ssl, data, callback) {
  184.             var url = (ssl ? GLIDE_API_URL_SECURE : GLIDE_API_URL) + endpoint;
  185.  
  186.             data.method = method;
  187.  
  188.             $jq.ajax({
  189.                 cache: false,
  190.                 url: url,
  191.                 dataType: "jsonp",
  192.                 data: data,
  193.                 success: function(d, s) { callback(d); },
  194.                 error: function(x, s, e) { callback({ success: false, message: "Your request could not be completed at this time, please try again later" }); }
  195.             });
  196.         },
  197.  
  198.         login = function(next) {
  199.             if (glideSession.token) {
  200.                 if (next)
  201.                     next();
  202.  
  203.                 return;
  204.             }
  205.  
  206.             var username = { value: "" };
  207.             var password = { value: "" };
  208.             var remember = { value: true };
  209.  
  210.             try {
  211.                 var logins = loginManager.findLogins({}, "chrome://glide", null, LOGIN_REALM);
  212.                 var loginInfo = null;
  213.  
  214.                 if (logins.length > 0) {
  215.                     loginInfo = logins[0];
  216.                     username.value = loginInfo.username;
  217.                     password.value = loginInfo.password;
  218.                 }
  219.  
  220.                 if (!prompt.promptUsernameAndPassword(null, "Glide OS Login", "Please enter your Glide Username and Password",
  221.                     username, password, "Remember Me", remember))
  222.                     return;
  223.  
  224.                 if (!remember.value && loginInfo)
  225.                     loginManager.removeLogin(loginInfo);
  226.                 else if (loginInfo) {
  227.                     if (username.value != loginInfo.username || password.value != loginInfo.password) {
  228.                         var oldInfo = loginInfo;
  229.  
  230.                         loginInfo = Components.classes["@mozilla.org/login-manager/loginInfo;1"].createInstance(Components.interfaces.nsILoginInfo);
  231.                         loginInfo.init("chrome://glide", null, LOGIN_REALM, username.value, password.value, "", "");
  232.  
  233.                         loginManager.modifyLogin(oldInfo, loginInfo);
  234.                     }
  235.                 }
  236.                 else {
  237.                     loginInfo = Components.classes["@mozilla.org/login-manager/loginInfo;1"].createInstance(Components.interfaces.nsILoginInfo);
  238.                     loginInfo.init("chrome://glide", null, LOGIN_REALM, username.value, password.value, "", "");
  239.  
  240.                     if (remember.value)
  241.                         loginManager.addLogin(loginInfo);
  242.                 }
  243.  
  244.                 glideSession.clear();
  245.  
  246.                 invokeService(ENDPOINT_SESSION, "login", true, { username: username.value, password: password.value }, function(d) {
  247.                     if (null == d || (null == d.message && !d.success)) {
  248.                         prompt.alert(null, "Glide OS Error", "Could not access the Glide OS at this time, please try again later");
  249.                     } else if (!d.success) {
  250.                         prompt.alert(null, "Glide OS Error", d.message);
  251.  
  252.                         login(next);
  253.                     }
  254.  
  255.                     glideSession.load(d);
  256.  
  257.                     application.storage.set(APP_STORAGE_SESSION_KEY, glideSession);
  258.  
  259.                     updateUI();
  260.  
  261.                     if (next)
  262.                         next();
  263.                 });
  264.             } catch (e) {
  265.                 prompt.alert(null, "Glide OS Error", "Could not log in to the Glide OS:\n\n" + e);
  266.  
  267.                 return;
  268.             }
  269.         },
  270.  
  271.         ensureLoggedIn = function(next) {
  272.             if (!glideSession.token) {
  273.                 var s = application.storage.get(APP_STORAGE_SESSION_KEY, {
  274.                     token: null,
  275.                     username: null,
  276.                     userId: null,
  277.                     accountId: null,
  278.                     email: null,
  279.                     fullName: null
  280.                 });
  281.  
  282.                 if (!s.token) {
  283.                     login(next);
  284.  
  285.                     return false;
  286.                 }
  287.  
  288.                 glideSession.load(s);
  289.             }
  290.  
  291.             return true;
  292.         },
  293.  
  294.         justLogin = function(evt) {
  295.             ensureLoggedIn(null);
  296.         },
  297.  
  298.         registerForGlide = function(evt) {
  299.             loadUrlInTab(GLIDE_REGISTER_URL);
  300.         },
  301.  
  302.         openGlide = function(evt) {
  303.             if (!ensureLoggedIn(openGlide))
  304.                 return;
  305.  
  306.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#csi=5&ser=5&offset=0&safety=1&sort=-1");
  307.         },
  308.  
  309.         openDesktop = function(evt) {
  310.             if (!ensureLoggedIn(openDesktop))
  311.                 return;
  312.  
  313.             loadUrlInTab(GLIDE_DESKTOP_URL + "?token=" + glideSession.token);
  314.         },
  315.  
  316.         logout = function(evt) {
  317.             var token = glideSession.token;
  318.             var confirmLogout = preferences.getBoolPref("extensions.glideos.confirmLogout");
  319.             var notAgain = { value: false };
  320.  
  321.             if (token && confirmLogout && !prompt.confirmCheck(null, "Glide OS Logout",
  322.                 "Are you sure you wish to log out?\n\nYou will have to log in again to access the Glide OS.\n\nAny Glide pages you have open should be closed,\nthese pages may not work properly after you log out.\n\n",
  323.                 "Do not ask me this again", notAgain))
  324.                 return;
  325.  
  326.             if (notAgain.value) {
  327.                 preferences.setBoolPref("extensions.glideos.confirmLogout", false);
  328.             }
  329.  
  330.             glideSession.clear();
  331.  
  332.             application.storage.set(APP_STORAGE_SESSION_KEY, {
  333.                 token: null,
  334.                 username: null,
  335.                 userId: null,
  336.                 accountId: null,
  337.                 email: null,
  338.                 fullName: null
  339.             });
  340.  
  341.             if (!token)
  342.                 return;
  343.  
  344.             invokeService(ENDPOINT_SESSION, "logout", true, { token: token }, function(d) { updateUI(); });
  345.         },
  346.  
  347.         addToBin = function(evt) {
  348.             var location = getCurrentDocument().location.href;
  349.             var title = getCurrentDocument().title;
  350.  
  351.             if (!ensureLoggedIn(addToBin))
  352.                 return;
  353.  
  354.             var categoryId = preferences.getCharPref("extensions.glide.lastBinCategory");
  355.  
  356.             var params = {
  357.                 inn: {
  358.                     glideSession: glideSession,
  359.                     invokeService: invokeService,
  360.                     ENDPOINT_FS: ENDPOINT_FS,
  361.                     categoryId: categoryId
  362.                 },
  363.                 out: null
  364.             };
  365.  
  366.             window.openDialog("chrome://glide/content/bin_category.xul", "", "centerscreen,modal,resizable=no", params).focus();
  367.  
  368.             if (params.out) {
  369.                 categoryId = params.out;
  370.  
  371.                 if ("NONE" == categoryId) {
  372.                     categoryId = null;
  373.                     preferences.setCharPref("extensions.glide.lastBinCategory", "");
  374.                 } else
  375.                     preferences.setCharPref("extensions.glide.lastBinCategory", categoryId);
  376.             }
  377.             else {
  378.                 return;
  379.             }
  380.  
  381.             invokeService(ENDPOINT_FS, "addtobinsingle", false,
  382.                 { token: glideSession.token, url: location, title: title, categoryId: categoryId },
  383.                 function(d) {
  384.                     if (null == d || (null == d.message && !d.success)) {
  385.                         prompt.alert(null, "Glide OS Error", "Could not access the Glide OS at this time, please try again later");
  386.                     } else if (!d.success) {
  387.                         prompt.alert(null, "Glide OS Error", d.message);
  388.                     } else if (d.message) {
  389.                         prompt.alert(null, "Glide OS", d.message);
  390.                     }
  391.                 });
  392.         },
  393.  
  394.         viewBin = function(evt) {
  395.             if (!ensureLoggedIn(viewBin))
  396.                 return;
  397.  
  398.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=1&csi=5&ser=5&offset=0&safety=1&sort=-1&sort=date&descending=true");
  399.         },
  400.  
  401.         promptType = function() {
  402.             var types = new Array();
  403.  
  404.             for (var i = 0; i < CAPTURE_TYPES.length; i++) {
  405.                 types.push(CAPTURE_TYPES[i].label);
  406.             }
  407.  
  408.             var selection = {};
  409.  
  410.             if (!prompt.select(null, "Select Format", "Please choose the import format for your selected items:", types.length, types, selection))
  411.                 return null;
  412.  
  413.             return CAPTURE_TYPES[selection.value].type;
  414.         },
  415.  
  416.         selectCaptureTarget = function(sync) {
  417.             var params = {
  418.                 inn: {
  419.                     glideSession: glideSession,
  420.                     invokeService: invokeService,
  421.                     ENDPOINT_FS: ENDPOINT_FS,
  422.                     sync: sync
  423.                 },
  424.                 out: null
  425.             };
  426.  
  427.             window.openDialog("chrome://glide/content/locator.xul", "", "centerscreen,modal,resizable=no", params).focus();
  428.  
  429.             return params.out;
  430.         },
  431.  
  432.         captureImport = function(evt) {
  433.             var location = getCurrentDocument().location.href;
  434.             var title = getCurrentDocument().title;
  435.  
  436.             if (!ensureLoggedIn(captureImport))
  437.                 return;
  438.  
  439.             var image = false;
  440.             var type = promptType();
  441.  
  442.             if (null == type)
  443.                 return;
  444.  
  445.             var targetId = selectCaptureTarget(false);
  446.  
  447.             if (!targetId)
  448.                 return;
  449.  
  450.             invokeService(ENDPOINT_FS, "capturesingle", false,
  451.                 { token: glideSession.token, type: type, url: location, title: title, targetId: targetId.value, image: image },
  452.                 function(d) {
  453.                     if (null == d || (null == d.message && !d.success)) {
  454.                         prompt.alert(null, "Glide OS Error", "Could not access the Glide OS at this time, please try again later");
  455.                     } else if (!d.success) {
  456.                         prompt.alert(null, "Glide OS Error", d.message);
  457.                     } else if (d.message) {
  458.                         prompt.alert(null, "Glide OS", d.message);
  459.                     }
  460.                 });
  461.         },
  462.  
  463.         captureBookmark = function(evt) {
  464.             var location = getCurrentDocument().location.href;
  465.             var title = getCurrentDocument().title;
  466.  
  467.             if (!ensureLoggedIn(captureBookmark))
  468.                 return;
  469.  
  470.             var targetId = selectCaptureTarget(false);
  471.  
  472.             if (!targetId)
  473.                 return;
  474.  
  475.             invokeService(ENDPOINT_FS, "capturebookmark", false,
  476.                 { token: glideSession.token, url: location, title: title, targetId: targetId.value },
  477.                 function(d) {
  478.                     if (null == d || (null == d.message && !d.success)) {
  479.                         prompt.alert(null, "Glide OS Error", "Could not access the Glide OS at this time, please try again later");
  480.                     } else if (!d.success) {
  481.                         prompt.alert(null, "Glide OS Error", d.message);
  482.                     } else if (d.message) {
  483.                         prompt.alert(null, "Glide OS", d.message);
  484.                     }
  485.                 });
  486.         },
  487.  
  488.         syncCapture = function(evt) {
  489.             var location = getCurrentDocument().location.href;
  490.             var title = getCurrentDocument().title;
  491.  
  492.             if (!ensureLoggedIn(syncCapture))
  493.                 return;
  494.  
  495.             var image = false;
  496.             var type = promptType();
  497.  
  498.             if (null == type)
  499.                 return;
  500.  
  501.             var targetId = selectCaptureTarget(true);
  502.  
  503.             if (!targetId)
  504.                 return;
  505.  
  506.             invokeService(ENDPOINT_FS, "capturesingle", false,
  507.                 { token: glideSession.token, type: type, url: location, title: title, targetId: targetId.value, image: image },
  508.                 function(d) {
  509.                     if (null == d || (null == d.message && !d.success)) {
  510.                         prompt.alert(null, "Glide OS Error", "Could not access the Glide OS at this time, please try again later");
  511.                     } else if (!d.success) {
  512.                         prompt.alert(null, "Glide OS Error", d.message);
  513.                     } else if (d.message) {
  514.                         prompt.alert(null, "Glide OS", d.message);
  515.                     }
  516.                 });
  517.         },
  518.  
  519.         uploadFiles = function(evt) {
  520.             if (!ensureLoggedIn(uploadFiles))
  521.                 return;
  522.  
  523.             loadUrlInTab(GLIDE_DESKTOP_URL + "/upload.aspx?token=" + glideSession.token);
  524.         },
  525.  
  526.         gotoMusic = function(evt) {
  527.             if (!ensureLoggedIn(gotoMusic))
  528.                 return;
  529.  
  530.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=33&ser=31&offset=0&safety=0&sort=modified&ac=Audio&q=");
  531.         },
  532.  
  533.         gotoVideos = function(evt) {
  534.             if (!ensureLoggedIn(gotoVideos))
  535.                 return;
  536.  
  537.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=34&ser=31&offset=0&safety=0&sort=modified&ac=Video&q=");
  538.         },
  539.  
  540.         gotoBookmarks = function(evt) {
  541.             if (!ensureLoggedIn(gotoBookmarks))
  542.                 return;
  543.  
  544.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=36&ser=31&offset=0&safety=0&sort=modified&ac=Url&q=");
  545.         },
  546.  
  547.         gotoOther = function(evt) {
  548.             if (!ensureLoggedIn(gotoOther))
  549.                 return;
  550.  
  551.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=37&ser=31&offset=0&safety=0&sort=modified&ac=Other&q=");
  552.         },
  553.  
  554.         gotoFolders = function(evt) {
  555.             if (!ensureLoggedIn(gotoFolders))
  556.                 return;
  557.  
  558.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=38&ser=31&offset=0&safety=0&sort=modified&ac=Container&mc=Personal&q=");
  559.         },
  560.  
  561.         gotoSlideshows = function(evt) {
  562.             if (!ensureLoggedIn(gotoSlideshows))
  563.                 return;
  564.  
  565.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=39&ser=31&offset=0&safety=0&sort=modified&ac=Container&mc=Image&q=");
  566.         },
  567.  
  568.         gotoMusicPlaylists = function(evt) {
  569.             if (!ensureLoggedIn(gotoMusicPlaylists))
  570.                 return;
  571.  
  572.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=40&ser=31&offset=0&safety=0&sort=modified&ac=Container&mc=Audio&q=");
  573.         },
  574.  
  575.         gotoVideoPlaylists = function(evt) {
  576.             if (!ensureLoggedIn(gotoVideoPlaylists))
  577.                 return;
  578.  
  579.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=41&ser=31&offset=0&safety=0&sort=modified&ac=Container&mc=Video&q=");
  580.         },
  581.  
  582.         gotoSentEmails = function(evt) {
  583.             if (!ensureLoggedIn(gotoSentEmails))
  584.                 return;
  585.  
  586.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=43&ser=31&offset=0&safety=0&sort=modified&ac=Webmail&mc=Sent&q=");
  587.         },
  588.  
  589.         gotoDraftEmails = function(evt) {
  590.             if (!ensureLoggedIn(gotoDraftEmails))
  591.                 return;
  592.  
  593.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=44&ser=31&offset=0&safety=0&sort=modified&ac=Webmail&mc=Draft&q=");
  594.         },
  595.  
  596.         gotoCalendars = function(evt) {
  597.             if (!ensureLoggedIn(gotoCalendars))
  598.                 return;
  599.  
  600.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=45&ser=31&offset=0&safety=0&sort=modified&ac=Container&mc=Event&q=");
  601.         },
  602.  
  603.         shareEngagePost = function(evt) {
  604.             var location = getCurrentDocument().location.href;
  605.             var title = getCurrentDocument().title;
  606.  
  607.             if (!ensureLoggedIn(shareEngagePost))
  608.                 return;
  609.  
  610.             loadUrlInTab(GLIDE_DESKTOP_URL + "/engage?token=" + glideSession.token + "&cp=1&url=" + encodeURIComponent(location) + "&title=" + encodeURIComponent(title.replace(/'/g, "'")));
  611.         },
  612.  
  613.         shareEngageGroup = function(evt) {
  614.             var location = getCurrentDocument().location.href;
  615.             var title = getCurrentDocument().title;
  616.  
  617.             if (!ensureLoggedIn(shareEngageGroup))
  618.                 return;
  619.  
  620.             loadUrlInTab(GLIDE_DESKTOP_URL + "/engage?token=" + glideSession.token + "&new=1&url=" + encodeURIComponent(location) + "&title=" + encodeURIComponent(title.replace(/'/g, "'")));
  621.         },
  622.  
  623.         engageNewPost = function(evt) {
  624.             if (!ensureLoggedIn(engageNewPost))
  625.                 return;
  626.  
  627.             loadUrlInTab(GLIDE_DESKTOP_URL + "/engage?token=" + glideSession.token + "&cp=1");
  628.         },
  629.  
  630.         engageNewGroup = function(evt) {
  631.             if (!ensureLoggedIn(engageNewGroup))
  632.                 return;
  633.  
  634.             loadUrlInTab(GLIDE_DESKTOP_URL + "/engage?token=" + glideSession.token + "&new=1");
  635.         },
  636.  
  637.         engageOpenGroups = function(evt) {
  638.             if (!ensureLoggedIn(engageOpenGroups))
  639.                 return;
  640.  
  641.             loadUrlInTab(GLIDE_DESKTOP_URL + "/engage?token=" + glideSession.token + "&box=i");
  642.         },
  643.  
  644.         engageOpenLatestPosts = function(evt) {
  645.             if (!ensureLoggedIn(engageOpenLatestPosts))
  646.                 return;
  647.  
  648.             loadUrlInTab(GLIDE_DESKTOP_URL + "/engage?token=" + glideSession.token);
  649.         },
  650.  
  651.         engageOpenMyLatestPosts = function(evt) {
  652.             if (!ensureLoggedIn(engageOpenMyLatestPosts))
  653.                 return;
  654.  
  655.             loadUrlInTab(GLIDE_DESKTOP_URL + "/engage?token=" + glideSession.token + "&q=%40" + glideSession.username);
  656.         },
  657.  
  658.         shareEmail = function(evt) {
  659.             var location = getCurrentDocument().location.href;
  660.             var title = getCurrentDocument().title;
  661.  
  662.             if (!ensureLoggedIn(shareEmail))
  663.                 return;
  664.  
  665.             loadUrlInNewWindow(GLIDE_WEBMAIL_URL + "/compose.aspx?token=" + glideSession.token + "&url=" + encodeURIComponent(location) + "&title=" + encodeURIComponent(title.replace(/'/g, "'")), 800, 600, false);
  666.         },
  667.  
  668.         emailNew = function(evt) {
  669.             if (!ensureLoggedIn(emailNew))
  670.                 return;
  671.  
  672.             loadUrlInNewWindow(GLIDE_WEBMAIL_URL + "/compose.aspx?token=" + glideSession.token, 800, 600, false);
  673.         },
  674.  
  675.         emailOpenInbox = function(evt) {
  676.             if (!ensureLoggedIn(emailOpenInbox))
  677.                 return;
  678.  
  679.             loadUrlInTab(GLIDE_WEBMAIL_URL + "/login.aspx?token=" + glideSession.token);
  680.         },
  681.  
  682.         shareGroup = function(evt) {
  683.             var location = getCurrentDocument().location.href;
  684.             var title = getCurrentDocument().title;
  685.  
  686.             if (!ensureLoggedIn(shareGroup))
  687.                 return;
  688.  
  689.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/create/project.aspx?token=" + glideSession.token + "&url=" + encodeURIComponent(location) + "&title=" + encodeURIComponent(title.replace(/'/g, "'")), 800, 600, false);
  690.         },
  691.  
  692.         groupNew = function(evt) {
  693.             if (!ensureLoggedIn(groupNew))
  694.                 return;
  695.  
  696.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/create/project.aspx?token=" + glideSession.token, 800, 600, false);
  697.         },
  698.  
  699.         gotoGroupInbox = function(evt) {
  700.             if (!ensureLoggedIn(gotoGroupInbox))
  701.                 return;
  702.  
  703.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=31&ser=31&offset=0&safety=0&sort=modified&ac=Group&mc=Inbox&q=");
  704.         },
  705.  
  706.         gotoGroupOutbox = function(evt) {
  707.             if (!ensureLoggedIn(gotoGroupOutbox))
  708.                 return;
  709.  
  710.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=31&ser=31&offset=0&safety=0&sort=modified&ac=Group&mc=Outbox&q=");
  711.         },
  712.  
  713.         shareMeeting = function(evt) {
  714.             var location = getCurrentDocument().location.href;
  715.             var title = getCurrentDocument().title;
  716.  
  717.             if (!ensureLoggedIn(shareMeeting))
  718.                 return;
  719.  
  720.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/create/chat.aspx?token=" + glideSession.token + "&url=" + encodeURIComponent(location) + "&title=" + encodeURIComponent(title.replace(/'/g, "'")), 800, 600, false);
  721.         },
  722.  
  723.         meetingNew = function(evt) {
  724.             if (!ensureLoggedIn(meetingNew))
  725.                 return;
  726.  
  727.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/create/chat.aspx?token=" + glideSession.token, 800, 600, false);
  728.         },
  729.  
  730.         gotoMeetingInbox = function(evt) {
  731.             if (!ensureLoggedIn(gotoMeetingInbox))
  732.                 return;
  733.  
  734.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=31&ser=31&offset=0&safety=0&sort=modified&ac=Chat&mc=Inbox&q=");
  735.         },
  736.  
  737.         gotoMeetingOutbox = function(evt) {
  738.             if (!ensureLoggedIn(gotoMeetingOutbox))
  739.                 return;
  740.  
  741.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=31&ser=31&offset=0&safety=0&sort=modified&ac=Chat&mc=Outbox&q=");
  742.         },
  743.  
  744.         writeNewPost = function(evt) {
  745.             var location = getCurrentDocument().location.href;
  746.             var title = getCurrentDocument().title;
  747.  
  748.             if (!ensureLoggedIn(writeNewPost))
  749.                 return;
  750.  
  751.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/write?token=" + glideSession.token + "&url=" + encodeURIComponent(location) + "&title=" + encodeURIComponent(title.replace(/'/g, "'")));
  752.         },
  753.  
  754.         writeNew = function(evt) {
  755.             if (!ensureLoggedIn(writeNew))
  756.                 return;
  757.  
  758.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/write?token=" + glideSession.token);
  759.         },
  760.  
  761.         gotoDocuments = function(evt) {
  762.             if (!ensureLoggedIn(gotoDocuments))
  763.                 return;
  764.  
  765.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=35&ser=31&offset=0&safety=0&sort=modified&ac=Document&q=");
  766.         },
  767.  
  768.         presenterNew = function(evt) {
  769.             if (!ensureLoggedIn(presenterNew))
  770.                 return;
  771.  
  772.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/ui/presenter?token=" + glideSession.token + "&mode=composer");
  773.         },
  774.  
  775.         crunchNew = function(evt) {
  776.             prompt.alert(null, "Glide OS", "Coming Soon");
  777.         },
  778.  
  779.         websiteNew = function(evt) {
  780.             if (!ensureLoggedIn(websiteNew))
  781.                 return;
  782.  
  783.             loadUrlInNewWindow(GLIDE_PUBLIC_URL + "/site.aspx?token=" + glideSession.token + "&id=" + EMPTY_GUID + "&edit=1");
  784.         },
  785.  
  786.         gotoWebsites = function(evt) {
  787.             if (!ensureLoggedIn(gotoWebsites))
  788.                 return;
  789.  
  790.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=42&ser=31&offset=0&safety=0&sort=modified&ac=Container&mc=UserWebSite&q=");
  791.         },
  792.  
  793.         openPhotoEdit = function(evt) {
  794.             if (!ensureLoggedIn(openPhotoEdit))
  795.                 return;
  796.  
  797.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/ui/photo.aspx?securityToken=" + glideSession.token);
  798.         },
  799.  
  800.         gotoPhotos = function(evt) {
  801.             if (!ensureLoggedIn(gotoPhotos))
  802.                 return;
  803.  
  804.             loadUrlInTab(GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=31&ser=31&offset=0&safety=0&sort=modified&ac=Image&q=");
  805.         },
  806.  
  807.         drawNew = function(evt) {
  808.             if (!ensureLoggedIn(drawNew))
  809.                 return;
  810.  
  811.             loadUrlInNewWindow(GLIDE_DESKTOP_URL + "/ui/drawing.aspx?token=" + glideSession.token);
  812.         },
  813.  
  814.         gotoDrawings = function(evt) {
  815.             if (!ensureLoggedIn(gotoDrawings))
  816.                 return;
  817.  
  818.             var url = GLIDE_URL + "/glide.aspx?token=" + glideSession.token + "#mode=2&csi=32&ser=31&offset=0&safety=0&sort=modified&ac=Image&mc=Drawing&q=";
  819.  
  820.             loadUrlInTab(url);
  821.         },
  822.  
  823.         openAddressBook = function(evt) {
  824.             if (!ensureLoggedIn(openAddressBook))
  825.                 return;
  826.  
  827.             var url = GLIDE_DESKTOP_URL + "/ui/addressbook.aspx?token=" + glideSession.token;
  828.  
  829.             loadUrlInNewWindow(url);
  830.         },
  831.  
  832.         openCalendar = function(evt) {
  833.             if (!ensureLoggedIn(openCalendar))
  834.                 return;
  835.  
  836.             var url = GLIDE_DESKTOP_URL + "/ui/calendar?stoken=" + glideSession.token;
  837.  
  838.             loadUrlInNewWindow(url);
  839.         };
  840.  
  841.     return {
  842.         init: init,
  843.         openToolbarButton: openToolbarButton,
  844.         tabSelected: tabSelected,
  845.         justLogin: justLogin,
  846.         registerForGlide: registerForGlide,
  847.         openGlide: openGlide,
  848.         openDesktop: openDesktop,
  849.         logout: logout,
  850.         addToBin: addToBin,
  851.         viewBin: viewBin,
  852.         captureImport: captureImport,
  853.         captureBookmark: captureBookmark,
  854.         syncCapture: syncCapture,
  855.         uploadFiles: uploadFiles,
  856.         gotoMusic: gotoMusic,
  857.         gotoVideos: gotoVideos,
  858.         gotoBookmarks: gotoBookmarks,
  859.         gotoOther: gotoOther,
  860.         gotoFolders: gotoFolders,
  861.         gotoSlideshows: gotoSlideshows,
  862.         gotoMusicPlaylists: gotoMusicPlaylists,
  863.         gotoVideoPlaylists: gotoVideoPlaylists,
  864.         gotoSentEmails: gotoSentEmails,
  865.         gotoDraftEmails: gotoDraftEmails,
  866.         gotoCalendars: gotoCalendars,
  867.         shareEngagePost: shareEngagePost,
  868.         shareEngageGroup: shareEngageGroup,
  869.         engageNewPost: engageNewPost,
  870.         engageNewGroup: engageNewGroup,
  871.         engageOpenGroups: engageOpenGroups,
  872.         engageOpenLatestPosts: engageOpenLatestPosts,
  873.         engageOpenMyLatestPosts: engageOpenMyLatestPosts,
  874.         shareEmail: shareEmail,
  875.         emailNew: emailNew,
  876.         emailOpenInbox: emailOpenInbox,
  877.         shareGroup: shareGroup,
  878.         groupNew: groupNew,
  879.         gotoGroupInbox: gotoGroupInbox,
  880.         gotoGroupOutbox: gotoGroupOutbox,
  881.         shareMeeting: shareMeeting,
  882.         meetingNew: meetingNew,
  883.         gotoMeetingInbox: gotoMeetingInbox,
  884.         gotoMeetingOutbox: gotoMeetingOutbox,
  885.         writeNewPost: writeNewPost,
  886.         writeNew: writeNew,
  887.         gotoDocuments: gotoDocuments,
  888.         presenterNew: presenterNew,
  889.         crunchNew: crunchNew,
  890.         websiteNew: websiteNew,
  891.         gotoWebsites: gotoWebsites,
  892.         openPhotoEdit: openPhotoEdit,
  893.         gotoPhotos: gotoPhotos,
  894.         drawNew: drawNew,
  895.         gotoDrawings: gotoDrawings,
  896.         openAddressBook: openAddressBook,
  897.         openCalendar: openCalendar
  898.     };
  899. } ();
  900.  
  901. window.addEventListener("load", function() {
  902.     gBrowser.addEventListener("DOMContentLoaded", function() {
  903.         glideExtension.init();
  904.     }, false);
  905. }, false);
  906.  
  907. gBrowser.tabContainer.addEventListener("TabSelect", function() {
  908.     glideExtension.tabSelected();
  909. }, false);
  910.